<template>
    <div>
        <!-- 搜索区 -->
        <el-form :inline="true" size="small" ref="form" label-width="80px" >
            <el-form-item label="物品类型">
                <el-select v-model="params.type" placeholder="请选择" clearable>
                    <el-option v-for="item in goods" :key="item.id" :label="item.name" :value="item.name"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="审核状态">
                <el-select v-model="params.checkStatus" placeholder="请选择" clearable>
                    <el-option label="待审核" value="待审核"></el-option>
                    <el-option label="通过" value="通过"></el-option>
                    <el-option label="不通过" value="不通过"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="关键字">
                <el-input v-model="params.name" placeholder="请输入关键字" clearable></el-input>
            </el-form-item>
        </el-form>

        <!-- 表格 -->
        <el-table :data="inventory.list" border style="width: 100%" size="small">
            <el-table-column fixed type="index" align="center" label="序号" width="80"></el-table-column>
            <el-table-column fixed label="申请人" align="center">
                <template slot-scope="scope">
                    {{scope.row.baseUser.realname}}
                </template>
            </el-table-column>
            <el-table-column prop="asset.code" label="物品编码" align="center" width="120"></el-table-column>
            <el-table-column prop="asset.name" label="物品名称" align="center"></el-table-column>
            <el-table-column prop="asset.type" label="物品类型" align="center" width="120"></el-table-column>
            <el-table-column prop="type" label="申请类别" align="center"></el-table-column>
            <el-table-column prop="reason" label="申请是由" align="center" width="150"></el-table-column>
            <el-table-column prop="asset.brand" label="品牌" align="center"></el-table-column>
            <el-table-column prop="asset.num" label="数量" align="center"></el-table-column>
            <el-table-column prop="applyforTime" label="领用日期" align="center" width="180">
                <template slot-scope="scope">
                    {{scope.row.applyforTime | dateFormat}}
                </template>
            </el-table-column>
            <el-table-column prop="checkOpinion" label="审核意见" align="center" width="120"></el-table-column>
            <el-table-column fixed="right" prop="checkStatus" label="状态" align="center">
                <template slot-scope="scope">
                    <el-tag class="pass" size="small">{{scope.row.checkStatus}}</el-tag>
                    <!-- <el-tag class="pass" v-if="scope.row.checkStatus = '通过'" size="small">通过</el-tag> -->
                    <!-- <el-tag class="noAuit" v-else-if="scope.row.checkStatus = '待审核'" size="small">待审核</el-tag>
                    <el-tag class="noPass" v-else size="small">未通过</el-tag> -->
                </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" align="center">
                <template slot-scope="scope">
                    <el-link v-if="scope.row.checkStatus == '通过'" disabled @click="auitHander(scope.row.id)" style="color:#c3c7ce">审核</el-link>
                    <el-link v-else @click="auitHander(scope.row)" class="auitting" :underline="false">审核</el-link>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
            layout="total, prev, pager, next"
            @current-change="pageHandler"
            :page-size="inventory.pageSize"
            :current-page="inventory.page"
            :total="inventory.total">
        </el-pagination>

        <!-- 审核模态框 -->
        <el-dialog title="申请审核" :visible.sync="dialogVisible" width="50%">
            <el-form ref="form" :model="form" label-width="80px">
                {{form}}
                <el-form-item label="物品编号" v-if="goods_row.asset">
                    <div>{{goods_row.asset.code}}</div>
                </el-form-item>
                <el-form-item label="物品名称" v-if="goods_row.asset">
                    <div>{{goods_row.asset.name}}</div>
                </el-form-item>
                <el-form-item label="品牌" v-if="goods_row.asset">
                    <div>{{goods_row.asset.brand}}</div>
                </el-form-item>
                <el-form-item label="规格参数" v-if="goods_row.asset">
                    <div>{{goods_row.asset.specification}}</div>
                </el-form-item>
                <el-form-item label="类型" v-if="goods_row.asset">
                    <div>{{goods_row.asset.type}}</div>
                </el-form-item>
                <el-form-item label="剩余数量" v-if="goods_row.asset">
                    <div>{{goods_row.asset.num}}</div>
                </el-form-item>
                <el-form-item label="申请类型">
                    <div>{{goods_row.type}}</div>
                </el-form-item>
                <el-form-item label="申请数量">
                    <div>{{goods_row.num}}</div>
                </el-form-item>
                
                <div class="details_img">
                    <img :src="goods_row.picture" alt="">
                </div>
                <el-form-item label="审批结果">
                    <el-radio v-model="pc.checkStatus" label="通过" value="通过">通过</el-radio>
                    <el-radio v-model="pc.checkStatus" label="不通过" value="不通过">不通过</el-radio>
                </el-form-item>
                <el-form-item label="审批意见">
                    <el-input type="textarea" v-model="pc.checkOpinion"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveHandler">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
import request from '@/utils/request'
import qs from 'qs'
// import moment from 'moment'
import { mapActions ,mapState} from 'vuex'
export default {
    data() {
        return {
            fileList:[],
            inventory:[],
            pc:{},
            params: {
                page: 1,
                pageSize: 10,
                applyforType: '领用,借用,申购',
                // checkStatus: '通过'
            },
            goods: [],
            dialogVisible: false,
            title: '',
            form: {
                checkStatus: '通过'
            },
            userInfo:'',
            form: {},
            detailsDialogVisible: false,
            goods_row: {},
            batchDialogVisible: false,
            batchForm: {}
        }
    },
    mounted() {
         // 分页查询物品信息
        this.queryAsset(this.params)
    },
    created() {
       

        // 查询所有物品类型
        this.findAllGoods()

        // 获取经办人信息
        this.getInfo()

    },
    computed: {
        ...mapState('user',['user'])
    },

    watch: {
        params: {
            handler: function() {
                this.queryAsset(this.params)
            },
            deep: true
        }
    },

    methods: {
        ...mapActions('user',['getInfo']),
        // 审核
        auitHander(row) {
            this.dialogVisible = true;
            this.goods_row = row;
        },
        // 确认审核
        saveHandler() {
            this.form = this.goods_row;
            this.form.checkStatus = this.pc.checkStatus
            this.form.checkOpinion = this.pc.checkOpinion
            request.post("/applyfor/saveOrUpdate",qs.stringify(this.form)).then(res => {
                this.$message({
                    message: res.message,
                    type: 'success'
                })
                this.queryAsset(this.params)
            })
        },

        dateFormat(row, column, cellValue, index) {
            return moment(cellValue).format('YYYY-MM-DD HH:mm:ss');
        },

        // 查询所有物品类型
        findAllGoods() {
            request.get("/assetType/findAll").then(res => {
                this.goods = res.data
            })
        },
        
        // 分页查询
        queryAsset() {
            request.post("/applyfor/pageQuery",qs.stringify(this.params)).then(res => {
                this.inventory = res.data
                console.log(res.data.list.checkStatus)
            })
        },

        // 分页
        pageHandler(page) {
            this.params.page = page
        }
    }
}
</script>

<style scoped>
    .pass {
        background-color: #eef9fb;
    }
    .noAuit {
        background-color: #fff8e6;
    }
    .noPass {
        background-color: #ffeded;
    }
    .auitting {
        color: #51c1d9;
    }
    .auitting:hover {
        color: #85d3e4;

    }
    .el-link {
        font-size: 12px;
    }
    .el-row {
        margin-bottom: 1rem;
    }
    .warn {
        color: #ff0000;
        font-size: 12px;
    }
    .download {
        color: #51c1d9;
        margin: 1rem 0 1rem 1rem;
    }
    .download:hover {
        color: #85d3e4;
    }
    .el-table {
        margin-top: 1rem;
    }
    .el-form-item >>> .el-form-item__label {
        height: 30px;
    }
    .el-form-item__content {
        height: 30px;
    }
    .details_img {
        /* float:right; */
        border: 1px solid #ccc;
        width: 120px;
        height: 120px;
        position: absolute;
        top: 6rem;
        right: 4rem;
        border-radius: 5px;
        padding: 5px;
    }
    .details_img img {
        width: 110px;
        height: 110px;
    }
    .el-dialog__body {
        position: relative;
    }
    .el-form-item {
        margin-bottom: 0;
        height: 30px;
    }
    .el-icon-edit {
        margin: 0 .5rem;
    }
    .el-dialog__wrapper >>> .el-dialog__header{
        background-color: #55c1d9;
    }
    .el-dialog__wrapper >>> .el-dialog__header span,.el-dialog__wrapper >>> .el-icon-close{
        color: #fff;
    }
</style>